package leetcode;

import org.junit.Test;

/**
 * @author: feiwang_6
 * @create: 2020/4/20 20:44
 * @description:
 */
public class MaxArea {
    @Test
    public void testMath(){
        int[] array = new int[]{1,8,6,2,5,4,8,3,7};
        System.out.println(getMaxArea(array));
    }

    /**
     * 盛最多水的容器(双指针)
     * @param array
     * @return
     */
    public int getMaxArea(int[] array){
        int l = 0, area = 0;
        int r = array.length - 1;
        while (l < r){
            if(array[l] > array[r]){
                area = Math.max(area, array[r] * (r - l));
                r--;
            }else {
                area = Math.max(area, array[l] * (r - l));
                l++;
            }
        }
        return area;
    }
}
